const express = require('express');

const add = express();

add.get('/server', (request, response) => {
    response.setHeader('Access-Control-Allow-Origin', '*')
    response.send('hello ajax')
})

add.post('/server', (request, response) => {
    response.setHeader('Access-Control-Allow-Origin', '*')
    response.send('hello ajax post')
})
add.all('/json-server', (request, response) => {
    //设置响应头，设置允许跨域
    response.setHeader('Access-Control-Allow-Origin', '*')
    const data = {
        name: 'leon'
    }
    let str = JSON.stringify(data);
    response.send(str);
})
add.get('/ie', (request, response) => {
    response.setHeader('Access-Control-Allow-Origin', '*')
    response.send('hello IE-33')
})

add.get('/delay', (request, response) => {
    response.setHeader('Access-Control-Allow-Origin', '*')
    setTimeout(() => {
        response.send('延时响应');
    }, 3000)
})

add.listen(8000, ()=>{
    console.log('服务已启动');
})